<?php
class Sys_brand_model extends CI_Model {

	public function __construct(){
		parent::__construct();
		$this->db = $this->load->database('default',true);
	}

	public function  query_brands() {
		$sql ="select * from sys_brand where  be_delete ='0' and  parent_id ='$parent_id' order by brand_id asc";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->result_array();
		}
	}

	public function query_brand_info($brand_id){
		$sql ="select * from  sys_brand where  be_delete ='0' and  brand_id ='$brand_id' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}

	public function query_brand_info_by_name($brand_name){
		$sql ="select * from  sys_brand where be_delete ='0' and  brand_name ='$brand_name' limit 1";
		$query	=$this->db->query($sql);
		if ($query->num_rows()>0) {
			return $query->row_array();
		}
	}
	public function insert_brand($brand){
		$brand['be_delete']=0;
		$this->db->insert('sys_brand',$brand);
	}
	public function update_brand($brand,$brand_id){
		$this->db->where('brand_id',$brand_id);
		$this->db->update('sys_brand',$brand);
	}

	public function set_delete_brand($brand_id){
		$sql ="update sys_brand set be_delete ='1' where brand_id='$brand_id'";
		$this->db->query($sql);
	}

	public function query_brand_list($start,$limit) {
		$sql ="select brand_id,brand_name from sys_brand where be_delete ='0'  order by brand_id asc limit $start,$limit";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}

	public function query_brand_num(){
		$sql ="select count(brand_id) as num from sys_brand  where be_delete ='0' ";
		$query =$this->db->query($sql);
		if ($query){
			$row =$query->row_array();
			return $row['num'];
		}
	}
	
	public function search_brand($keyword) {
		$keyword =$this->db->escape_like_str($keyword);
		$sql ="select brand_id as id ,
					brand_name as name 
				from sys_brand 
				where be_delete ='0'  
				and brand_name like '%$keyword%' 
				order by brand_id asc ";
		$query =$this->db->query($sql);
		if ($query) {
			return $query->result_array();
		}
	}
}
?>